import { dialog, ipcMain } from 'electron'
import { initMainMenu } from '../mainMenu/index'

export const initPrintList = (win, printLiving) => {
  ipcMain.handle('getPrintList', async (event, isShowMessage) => {
    try {
      const list = await win.webContents.getPrintersAsync()
      printLiving.setBrowserWindowList(list)
      initMainMenu(win, list)
      isShowMessage && dialog.showMessageBox(win, { title: '打印组件', message: '刷新打印列表成功!' })
      return list
    } catch (error) {
      console.log('error', error)
    }
  })

  ipcMain.handle('suspendChange', async () => {
    return printLiving.suspendChange()
  })

  ipcMain.handle('queueClearAll', async () => {
    return printLiving.queueClearAll()
  })
}
